package com.pet.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pet.server.domain.entity.PetOwner;
import com.pet.server.mapper.PetOwnerMapper;
import com.pet.server.service.IPetOwnerService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PetOwnerServiceImpl implements IPetOwnerService {
  private final PetOwnerMapper petMasterMapper;

  @Override
  public boolean addNewPetOwner(PetOwner petMaster) {
    return petMasterMapper.insertOrUpdate(petMaster) > 0;
  }

  @Override
  public boolean delPetOwnerSelectiveById(int id) {
    return petMasterMapper.deleteById(id) > 0;
  }

  @Override
  public boolean updatePetOwnerSelective(PetOwner petMaster) {
    return petMasterMapper.insertOrUpdate(petMaster) > 0;
  }

  @Override
  public List<PetOwner> getAllPetOwnerList(int pageNo, int pageSize, PetOwner petMaster) {
    QueryWrapper<PetOwner> queryWrapper = new QueryWrapper();
    //
    //    if ((petMaster.getMasterName() != null) &&
    // !("".equalsIgnoreCase(petMaster.getMasterName()))) {
    //      queryWrapper.like("name", petMaster.getMasterName());
    //    }
    //
    //    if ((petMaster.getMasterNickname() != null)
    //        && !("".equalsIgnoreCase(petMaster.getMasterNickname()))) {
    //      queryWrapper.like("nickname", petMaster.getMasterNickname());
    //    }
    //
    //    if ((petMaster.getMasterAddress() != null)
    //        && !("".equalsIgnoreCase(petMaster.getMasterAddress()))) {
    //      queryWrapper.like("address", petMaster.getMasterAddress());
    //    }
    //
    //    if ((petMaster.getMasterPhone() != null)
    //        && !("".equalsIgnoreCase(petMaster.getMasterPhone()))) {
    //      queryWrapper.like("phone", petMaster.getMasterPhone());
    //    }
    //
    //    if ((petMaster.getMasterArea() != null) &&
    // !("".equalsIgnoreCase(petMaster.getMasterArea()))) {
    //      queryWrapper.like("area", petMaster.getMasterArea());
    //    }

    Page<PetOwner> page = petMasterMapper.selectPage(new Page<>(pageNo, pageSize), queryWrapper);
    List<PetOwner> list = page.getRecords();

    return list;
  }

  @Override
  public PetOwner getPetOwnerSelectiveById(int id) {
    return petMasterMapper.selectById(id);
  }
}

// ~ Formatted by Jindent --- http://www.jindent.com
